﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.ADService;
using AvatarHelper;
using Avatar.Model;

public partial class Management_JobADCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (var _adc = DBHelper.GetDataContext())
            {
                GridView1.DataSource = _adc.ADCategory.ToList();
                GridView1.DataBind();
            }
        }
    }
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        try
        {
            ADCategoryManager.ADCategorySave(string.IsNullOrEmpty(txt_ID.Value) ? Guid.Empty : new Guid(txt_ID.Value),
                txt_ADCategoryName.Text,
                string.IsNullOrEmpty(txt_Height.Text) ? 0 : Convert.ToInt32(txt_Height.Text),
                string.IsNullOrEmpty(txt_Width.Text) ? 0 : Convert.ToInt32(txt_Width.Text),
                string.IsNullOrEmpty(txt_Column.Text) ? 0 : Convert.ToInt32(txt_Column.Text),
                string.IsNullOrEmpty(txt_Row.Text) ? 0 : Convert.ToInt32(txt_Row.Text));

            Response.Redirect(Request.Url.ToString());
        }
        catch (Exception _e)
        {
            lbl_Error.Text = _e.Message;
        }
    }
    protected void btn_Edit_Click(object sender, EventArgs e)
    {
        Button _btn=sender as Button;
        Guid _id = string.IsNullOrEmpty(_btn.CommandArgument) ? Guid.Empty : new Guid(_btn.CommandArgument);
        var _jobADCategory = ADCategoryManager.GetADCategory(_id);
        if (_jobADCategory != null)
        {
            txt_ID.Value = _jobADCategory.ID.ToString();
            txt_ADCategoryName.Text = _jobADCategory.CategoryName;
            txt_Column.Text = _jobADCategory.MaxColumn.ToString();
            txt_Height.Text = _jobADCategory.Height.ToString();
            txt_Row.Text = _jobADCategory.MaxRow.ToString();
            txt_Width.Text = _jobADCategory.Width.ToString();
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.Url.ToString());
    }
}
